<script lang="ts" setup>
	import { ref } from "vue";
	import {
		useRouter
	} from 'uni-mini-router'
	import {
		onShow,
		onHide,
		onLoad
	} from '@dcloudio/uni-app'
	let searchWord = ref('')
	let type = ref('')
	let router = useRouter()
	let pageObj = ref({})
	let marketHistory = ref([])
	if (uni.getStorageSync('marketHistory')) {
		marketHistory.value = marketHistory.value.concat(uni.getStorageSync('marketHistory'))
		// console.log(marketHistory.value);
	}
	const searchResult = () => {
		marketHistory.value = marketHistory.value.concat(searchWord.value)
		uni.setStorageSync('marketHistory', marketHistory.value)
		router.push({
			name: "marketResult",
			params: {
				key: searchWord.value,
				data: JSON.stringify(pageObj.value)
			}
		})
	}
	const deleteHis = () => {
		marketHistory.value = []
		uni.removeStorageSync('marketHistory')
	}
	onLoad((options) => {
		type.value = options.type
		pageObj.value = JSON.parse(options.data)
		// console.log(type.value);
	})
</script>
<template>
	<view class="navbar">
		<u-navbar :placeholder="true" leftText="" title="" auto-back>
			<template #center>
				<view style="width: 70%;">
					<u-search placeholder="ssss" v-model="searchWord" :showAction="false"
						@search="searchResult"></u-search>
				</view>
			</template>
			<template #right>
				<view class="" @click="router.back()">
					取消
				</view>
			</template>
		</u-navbar>
	</view>
	<view class="historySearch">
		<text>历史搜索</text>
		<u-icon name="trash" size="20" @click="deleteHis"></u-icon>
	</view>
	<view class="hsCon">
		<text v-for="(item,index) in marketHistory" :key="index">{{ item }}</text>
	</view>
</template>
<style lang="scss">
	.navbar {
		width: 100%;
		height: 100rpx;
	}

	.historySearch {
		width: 90%;
		margin: 30rpx auto;
		display: flex;
		justify-content: space-between;
		font-weight: 600;
		font-size: 32rpx;
	}

	.hsCon {
		width: 90%;
		margin: 30rpx auto;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;

		text {
			padding: 4rpx 30rpx;
			background-color: #e7e7e7;
			border-radius: 30rpx;
			color: #7e8186;
			font-size: 24rpx;
			margin: 10rpx 10rpx;
		}
	}
</style>